package com.yanqu.road.server.cmd.activity.unionwar;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.pb.activity.unionwar.UnionWarActivityServerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.unionwar.UnionPhaseWarMgr;
import com.yanqu.road.server.manger.activity.unionwar.UnionWar;
import com.yanqu.road.server.manger.activity.unionwar.UnionWarActivityMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_UNION_WAR_MATCH_VIDEO_DETAIL,desc = "精彩对阵-过程")
public class UnionWarMatchVideoDetailCmd extends AbstractCommand {

    private int activityId;
    private int phase;
    private int session;
    private String unionUid;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        UnionWarActivityServerProto.MatchVideoDetailReqMsg reqMsg = UnionWarActivityServerProto.MatchVideoDetailReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        phase = reqMsg.getPhase();
        session = reqMsg.getSession();
        unionUid = reqMsg.getUnionUid();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActivityInfo activityInfo = UnionWarActivityMgr.getOpenActivityInfo(activityId);
        if(activityInfo == null){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        UnionWar unionWar = UnionPhaseWarMgr.getUnionWarMap().get(activityId);
        if(unionWar == null){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }

        int groupId = GameUnionActivityGroupMgr.getGroupId(activityId, unionUid);
        UnionWarActivityServerProto.MatchVideoDetailReqMsg.Builder reqMsg = UnionWarActivityServerProto.MatchVideoDetailReqMsg.newBuilder();
        reqMsg.setActivityId(activityId);
        reqMsg.setPhase(phase);
        reqMsg.setSession(session);
        reqMsg.setUnionUid(unionUid);
        player.sendUnionActivityGroupPacket(Protocol.C_UNION_WAR_MATCH_VIDEO_DETAIL, reqMsg, unionWar.getActivityInfo().getActivityId(), groupId);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            UnionWarActivityServerProto.MatchVideoDetailRespMsg.Builder reqMsg = UnionWarActivityServerProto.MatchVideoDetailRespMsg.newBuilder();
            reqMsg.setActivityId(activityId);
            reqMsg.setPhase(phase);
            reqMsg.setSession(session);
            player.sendPacket(Protocol.U_UNION_WAR_MATCH_VIDEO_DETAIL, reqMsg);
        }
    }
}
